package com.ljkj.blockpay.presenter;

import android.content.Context;

import androidx.annotation.NonNull;

import com.kongzue.baseokhttp.HttpRequest;
import com.kongzue.baseokhttp.listener.JsonResponseListener;
import com.kongzue.baseokhttp.util.JsonMap;
import com.kongzue.baseokhttp.util.Parameter;
import com.ljkj.blockpay.basedata.BasePresenterImpl;
import com.ljkj.blockpay.basedata.BaseView;
import com.ljkj.blockpay.network.ApiToCConfig;
import com.ljkj.blockpay.presenter.inter.MinePresenterInter;

/**
 * Created by yp on 2022/3/1
 */
public class MinePresenter extends BasePresenterImpl<MinePresenterInter.MinePresenterInterView> implements MinePresenterInter.MinePresenter {

    public MinePresenter(@NonNull Context context, @NonNull MinePresenterInter.MinePresenterInterView view) {
        super(context, view);
    }


    @Override
    public void logout() {
        JsonMap jsonMap = new JsonMap();
        HttpRequest.JSONPOST(getContext(), ApiToCConfig.URL_LOGINOUT, jsonMap, new JsonResponseListener() {
                    @Override
                    public void onResponse(JsonMap main, Exception error) {
                        if (main.getInt("code") == 0){
                            JsonMap data = main.getJsonMap("data");
                            getView().logoutSuccess(jsonMap);
                        }
                    }
                });
    }

    //查询用户的信息
    @Override
    public void userInfo() {
        HttpRequest.GET(getContext(), ApiToCConfig.USER_INFO, new Parameter(), new JsonResponseListener() {
            @Override
            public void onResponse(JsonMap main, Exception error) {
                if (main.getInt("code") == 0){
                    JsonMap jsonMap = new JsonMap();
                    JsonMap data = jsonMap.getJsonMap("data");
                    getView().searchInfoSuccess(data);
                }
            }
        });
    }


}

